/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package downloader.IHM;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JTextField;

/**
 *
 * @author Julien
 */
public class SettingsDialog extends JDialog implements ActionListener, WindowListener {
    
    private MainWindows myMainWindows;
    private JTextField targetFolderTitle;
    private JTextField targetFolderSetting;
    private JButton okButton = new JButton("OK");
    private JButton cancelButton = new JButton("Cancel");

    public SettingsDialog(MainWindows myMainWindows){
        this.myMainWindows = myMainWindows;
        this.setTitle("Settings");
        this.setVisible(false);
        this.setLayout(new GridLayout(2,2));
        this.setLocation(200, 200);

        targetFolderTitle = new JTextField("Download Folder :");
        targetFolderTitle.setEditable(false);
        this.add(targetFolderTitle);

        targetFolderSetting = new JTextField(myMainWindows.getMyTargetFolder());
        targetFolderSetting.setEditable(true);
        targetFolderSetting.setSize(50,100);
        this.add(targetFolderSetting);

        okButton.addActionListener(this);
        this.add(okButton);

        cancelButton.addActionListener(this);
        this.add(cancelButton);
    }

    public void showSettingsDialog(){
        this.pack();
        this.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        JButton temp = (JButton) e.getSource();
        if (temp.getText().equalsIgnoreCase("OK")){
            myMainWindows.setMyTargetFolder(targetFolderSetting.getText());
            this.setVisible(false);
        }
        if (temp.getText().equalsIgnoreCase("Cancel")){
            this.setVisible(false);
        }
    }

    public void windowOpened(WindowEvent e) {
    }

    public void windowClosing(WindowEvent e) {
    }

    public void windowClosed(WindowEvent e) {
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }

}
